import Vue from 'vue'
import Vuex from 'vuex'

import user from './modules/user'
import poster from './modules/poster' // 推广营销 - 海报
import news from './modules/news' // 消息
import accessory from './modules/accessory' // 消息
import carGoods from './modules/carGoods' // 消息
import afterSales from './modules/afterSales' // 维保
import indexHome from './modules/indexHome' // 首页

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    companyId: '', //公司id
    needPageBack: false, //登录后是否需要返回之前页面
    province: '四川省',  // 省份
    city: '', //城市
    latitude: '', //纬度
    longitude: '', //经度
    isLogin: false, //是否登录
    tid: '', //用户id
    token: '', //账户token
    userInfoDetail: {}, //用户详细信息
    carConfig: {
      specifications: {}, //规格
      brand: {}, //品牌
      series: {}, //系列
      configuration: {}, //配置
      color: { //外观颜色
        inDecoration: '', // 内饰:
        outDecoration: '', // 外饰
      }
    },
    activeConfig: {}, //当前选择车辆配置信息

    // 默认头像图片
    defaultHeaderImg: '',

  },
  mutations: {
    //存储公司id
    setCompanyId(state, companyId) {
      state.companyId = companyId
    },
    //设置返回页面标记
    setNeedPageBack(state, data) {
      state.needPageBack = data
    },

    // 选择品牌
    setBrand(state, data) {
      // console.log('车辆选择数据',state, data)
      state.carConfig.brand = {
        id: data.Bid,
        name: data.Brand
      }
    },
    // 选择系列
    setSeries(state, data) {
      // console.log('车辆选择数据',state, data)
      state.carConfig.series = {
        id: data.CarTypeId,
        name: data.CarTypeName
      }
    },
    setConfig(state, data) {
      state.carConfig.configuration = {
        id: data.Id,
        name: data.Name,
        price: data.Factoryprice
      }
      state.activeConfig = data
      console.log('车辆选择数据', state, data)
    },
    setAddress(state, address) {
      state.province = address.province
      state.city = address.city
    },
    //经纬度
    setLatitude(state, latitude) {
      state.latitude = latitude
      console.log('latitude', '维度')
    },
    setLongitude(state, longitude) {
      state.longitude = longitude
      console.log('longitude', '维度')
    },
    //存储用户信息
    setUserInfo(state, data) {
      state.tid = data.tid
      state.token = data.token
    },

    //存储用户详细信息
    setUserInfoDetail(state, data) {
      state.userInfoDetail = Object.assign({}, data)
    },
    //存储用户角色权限
    setUserRole(state, data) {
		  state.userInfoDetail.role = data
    },

    resetInfo(state) {
      state.userInfoDetail = {}
    },

  },
  actions: {
    getCompanyId({
      commit
    }, companyId) {
      commit('setCompanyId', companyId)
    },
    changeAddress({
      commit
    }, address) {
      commit('setAddress', address)
    },
    changeLatitude({
      commit
    }, latitude) {
      commit('setLatitude', latitude)
    },
    changeLongitude({
      commit
    }, longitude) {
      commit('setLongitude', longitude)
    },
  },
  getters: {

  },
  modules: {
    user,
    poster,
    news,
    accessory,
    carGoods,
    afterSales,
    indexHome
  },
})

export default store
